# -*- coding: utf-8 -*-
'''
Created on 2011-8-21

@author: zxz
'''

from sqlalchemy import Column, SmallInteger, Integer, BigInteger, FLOAT, String, Text, DateTime
from datasource import Base
from common.DateUtil import getStdTimeStr

class Stream(Base):
    ''' 分享的信息 '''
    __tablename__ = 'stream'
    id = Column(BigInteger, primary_key=True)
    uid = Column(BigInteger, nullable=False)
    # json数据 : content, items{pic, msg}，总体长度限制4K
    content = Column(Text, nullable=False)
    tags = Column(String(64), nullable=True)
    place_id = Column(BigInteger, nullable=True)
    latitude = Column(FLOAT, nullable=True)
    longitude = Column(FLOAT, nullable=True)
    gmt_create = Column(DateTime, nullable=False)
    gmt_modified = Column(DateTime, nullable=False)

    def __init__(self, uid, content, tags, place_id, latitude, longitude, gmt_create, gmt_modified):
        self.uid = uid
        self.content = content
        self.tags = tags
        self.place_id = place_id
        self.latitude = latitude
        self.longitude = longitude
        self.gmt_create = gmt_create
        self.gmt_modified = gmt_modified

    def __repr__(self):
        return '<Stream %r>' % self.id

    def entity(self):
        return {'id':self.id, 'uid' : self.uid, 'content' : self.content, 'tags' : self.tags, 'place_id' : self.place_id, 'latitude' : self.latitude, 'longitude' : self.longitude, 'gmt_create' : getStdTimeStr(self.gmt_create), 'gmt_modified' : getStdTimeStr(self.gmt_modified)}

class StreamMain(Base):
    ''' 主墙信息 '''
    __tablename__ = 'stream_main'
    id = Column(BigInteger, primary_key=True)
    uid = Column(BigInteger, nullable=False)
    sid = Column(BigInteger, nullable=False)
    publisher = Column(BigInteger, nullable=False)
    gmt_create = Column(DateTime, nullable=False)

    def __init__(self, uid, sid, publisher, gmt_create):
        self.uid = uid
        self.sid = sid
        self.publisher = publisher
        self.gmt_create = gmt_create

    def __repr__(self):
        return '<StreamMain %r>' % self.id

    def entity(self):
        return {'id':self.id, 'uid' : self.uid, 'sid' : self.sid, 'publisher' : self.publisher, 'gmt_create' : getStdTimeStr(self.gmt_create)}
